package org.zyzboole.base.encrypt.crypto;

import cn.hutool.crypto.symmetric.AES;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
 * @author xuhao
 * @date 2020/11/4
 * @description Aes加密工具类
 */
@Slf4j
public class AesKit {

    private static AES aes;
    private static final String KEY = "6f7a401a7df78d69ef45cf3d141798f8";
    private static final String IV = "1234567812345678";

    static {
        aes = new AES("CBC", "PKCS5Padding", KEY.getBytes(StandardCharsets.UTF_8), IV.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * 功能描述: AES加密--为base64的code
     *
     * @param content
     * @return java.lang.String
     * @author xuhao
     */
    public static String encryptBase64(String content) {
        return aes.encryptBase64(content);
    }


    /**
     * 功能描述: AES解密--并解密base64
     *
     * @param encryptStr
     * @return java.lang.String
     * @author xuhao
     */
    public static String decrypt(String encryptStr) {
        return aes.decryptStr(encryptStr);
    }

    public static void main(String[] args) {
        String content = "zxcv1234";
        System.out.println(encryptBase64(content));
        String decryptStr = decrypt("LfgQAdcRERqZBiTmVUodbw==");
        System.out.println(decryptStr);
    }

}
